<!-- 公告页面2.0 -->
<template>
  <div class="kg-detail animate__animated animate__zoomIn">
    <div v-if="!loadingFlag" class="notice-title">
      <dv-decoration-11 style="width: 25%; height: 80%; font-size: 0.26rem"
        >知识库详情</dv-decoration-11
      >
      <div class="goback">
        <GoBack></GoBack>
      </div>
    </div>
    <div v-if="!loadingFlag" class="notice-info">
      <dv-border-box-1>
        <div class="info-box">
          <div class="info-title">
            <h1>{{ title }}</h1>
            <div class="pdf-show" v-if="pdfData.length > 0">
              <span
                v-for="(item, i) in pdfData"
                :key="i"
                @click="handlePdf(item.url)"
                >附件:{{ item.title }}</span
              >
            </div>
          </div>
          <div class="info-content">
            <div id="notiveInfo" v-html="info"></div>
          </div>
        </div>
      </dv-border-box-1>
    </div>
    <!-- 弹出  -->
    <el-dialog
       v-if="!loadingFlag"
      title="PDF预览"
      :visible.sync="dialogVisible"
      width="40%"
      :modal-append-to-body = 'false'
      :append-to-body = 'true'
    >
      <PublicPdf :url="url"></PublicPdf>
    </el-dialog>
    <!-- loading -->
    <div v-if="loadingFlag" class="e-loading">
      <dv-loading style="color: #fff; opcity: 0.5"
        >数据加载中...</dv-loading
      >
    </div>
  </div>
</template>

<script>
import PublicPdf from "../container/PublicPdf"
export default {
  //import引入的组件需要注入到对象中才能使用
  components: { PublicPdf },
  data() {
    //这里存放数据
    return {
      title: "XXX知识库",
      info: "kgkgkgkgkgkgkg",
      pdfData: [],
      dialogVisible: false,
      url: '',
      loadingFlag: true
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    async init() {
      let id = this.$route.params.id;
      //   console.log('等待接口，获取ID为'+id+'的kg详情');
      //   return
      let ret = await this.$http.postGetKnowledgeDetail({ id });
      if (ret.data.errorCode != 0) {
        return console.log("后台报错, 错误码：" + ret.data.errorCode);
      }

      let data = ret.data.data;
      console.log(data);
      this.title = data.KnowledgeDetail.title;
      this.info = data.KnowledgeDetail.content;

      // PDF获取
      let upList = data.Knowledgeuplist;
      upList.forEach((ele) => {
        if (ele.com) {
          this.pdfData.push(ele);
        }
      });

      this.loadingFlag = false
    },

    handlePdf(url) {
      let parget = this.$http.baseURL + url;
      // console.log(parget);
      this.url = parget
      this.dialogVisible = true
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    // console.log(this.$route.params.id + " 是ID");
    this.init();
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeRouteEnter(to, form, next) {
    if (JSON.stringify(to.params) == "{}") {
      to.meta.isBack = true;
    } else {
      to.meta.isBack = false;
    }
    next();
  },
  activated() {
    if (!this.$route.meta.isBack) {
      console.log("需要刷新");
      this.init();
    } else {
      console.log("缓存页面");
    }
  },
};
</script>
<style lang='less' scoped>
//@import url(); 引入公共css类
.kg-detail {
  width: 100%;
  height: 100%;
  position: relative;
  .notice-title {
    width: 100%;
    height: 15%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    color: @FontColor;
    .goback {
      position: absolute;
      left: 0;
      top: 2%;
    }
  }
  .notice-info {
    width: 70%;
    height: 85%;
    margin: 0 auto;
    position: relative;
    .info-box {
      width: 90%;
      height: 90%;
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
      background-color: rgba(255, 255, 255, 0.1);
      border-radius: 0.08rem;
      padding: 1% 2%;
      .info-title {
        width: 100%;
        height: 20%;
        border-bottom: 1px solid #ccc;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        h1 {
          font-size: 0.34rem;
          color: @FontColor;
          flex: 1;
          display: flex;
          justify-content: center;
          align-items: center;
        }
        .pdf-show {
          width: 100%;
          flex: 1;
          display: flex;
          justify-content: flex-end;
          align-items: center;
          overflow: auto;
          span {
            font-size: 0.22rem;
            color: @Green;
            text-decoration: underline;
            margin: 0 0.2rem;
            white-space: nowrap;
          }
        }
      }
      .info-content {
        height: 70%;
        padding: 4% 2%;
        // background-color: #ccc;
        #notiveInfo {
          color: #eee;
          box-sizing: border-box;
          padding: 0 5%;
          width: 100%;
          height: 100%;
          font-size: 0.28rem;
          text-align: left;
          line-height: 1.5;
          text-indent: 2em;
          overflow: auto;
        }
      }
    }
  }
}
</style>